<h:form id="formDotacao" 
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:pe="http://primefaces.org/ui/extensions"
        xmlns:f="http://java.sun.com/jsf/core">

    <script language="JavaScript" src = "scripts/script.js"/>

    <h:panelGrid style="width: 100%">

        <h:panelGrid columns="2" style="width: 100%">

            <h:panelGroup>

                <h:outputLabel value="Programa" /><br/>

                <p:selectOneMenu value="#{dotacaoBean.dotacao.programa}" 
                                 style="width: 190px" >

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{dotacaoBean.programas}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="acao orgao unidadeOrcamentaria
                                                  valorPrevisto" />

                    <p:ajax event="change" 
                            listener="#{dotacaoBean.dotacaoService
                                        .obterDotacao(dotacaoBean.dotacao)}" 
                            update="dotacao" />

                </p:selectOneMenu>

            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Ação" /><br/>

                <p:selectOneMenu id="acao"
                                 value="#{dotacaoBean.dotacao.acao}" 
                                 style="width: 190px" >

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{dotacaoBean.acoes}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="tipoAcao descricao valorPrevisto" 
                            listener="#{dotacaoBean.dotacaoService.obterValorPrevisto(dotacaoBean.dotacao)}" />

                    <p:ajax event="change" 
                            listener="#{dotacaoBean.dotacaoService
                                        .obterDotacao(dotacaoBean.dotacao)}" 
                            update="dotacao" />

                </p:selectOneMenu>

            </h:panelGroup>
        </h:panelGrid>

        <h:panelGrid columns="2" style="width: 100%">

            <h:panelGroup>

                <h:outputLabel value="Órgão" /><br/>

                <p:inputText id="orgao"
                             value="#{dotacaoBean.dotacao.orgao}" 
                             readonly="true" 
                             style="width: 93%" />

            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Unidade Orçamentária" /><br/>

                <p:inputText id="unidadeOrcamentaria"
                             value="#{dotacaoBean.dotacao.unidadeOrcamentaria}" 
                             readonly="true" 
                             style="width: 93%" />

            </h:panelGroup>

        </h:panelGrid>

        <h:panelGrid columns="2" style="width: 100%">            

            <h:panelGroup>

                <h:outputLabel value="Função" /><br/>

                <p:selectOneMenu value="#{dotacaoBean.dotacao.funcao}" 
                                 style="width: 190px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{dotacaoBean.funcoes}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="subFuncao" />

                    <p:ajax event="change" 
                            listener="#{dotacaoBean.dotacaoService
                                        .obterDotacao(dotacaoBean.dotacao)}" 
                            update="dotacao" />

                </p:selectOneMenu>

            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Subfunção" /><br/>

                <p:selectOneMenu id="subFuncao"
                                 value="#{dotacaoBean.dotacao.subFuncao}" 
                                 style="width: 190px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{dotacaoBean.subFuncoes}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" 
                            listener="#{dotacaoBean.dotacaoService
                                        .obterDotacao(dotacaoBean.dotacao)}" 
                            update="dotacao" />

                </p:selectOneMenu>

            </h:panelGroup>

        </h:panelGrid>

        <h:panelGrid columns="2" style="width: 100%">            

            <h:panelGroup>

                <h:outputLabel value="Tipo de ação" /><br/>

                <p:inputText id="tipoAcao"
                             value="#{dotacaoBean.dotacao.tipoDeAcao}" 
                             readonly="true" 
                             style="width: 93%" />

            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Dotação"/><br/>

                <p:inputText id="dotacao"
                             value="#{dotacaoBean.dotacao.dotacao}" 
                             style="width: 93%" />

            </h:panelGroup>

        </h:panelGrid>

        <h:panelGrid columns="1" style="width: 100%">            

            <h:panelGroup>

                <h:outputLabel value="Descrição"/><br/>

                <p:inputText id="descricao"
                             value="#{dotacaoBean.dotacao.descricao}" 
                             style="width: 97%" />

            </h:panelGroup>

        </h:panelGrid>

        <h:panelGrid columns="2" style="width: 100%" >       

            <h:panelGroup>

                <h:outputLabel value="Unidade Gestora" /><br/>

                <p:selectOneMenu value="#{dotacaoBean.dotacao.unidadeGestora}" 
                                 style="width: 96%">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{dotacaoBean.unidadesGestora}" />
                    <f:converter converterId="simpleEntityConverter" />
                </p:selectOneMenu>

            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Valor Previsto"/><br/>

                <pe:inputNumber id="valorPrevisto"
                                value="#{dotacaoBean.dotacao.valorPrevisto}" 
                                required="true" requiredMessage="Campo valor previsto obrigatorio" 
                                symbol="R$" decimalSeparator="," thousandSeparator="." 
                                style="width: 93%" />

            </h:panelGroup>

        </h:panelGrid>

    </h:panelGrid>

    <hr/>

    <p:commandButton id="btnGravar" value="Gravar" 
                     actionListener="#{dotacaoBean.adicionarEditarFim}"
                     update="formDotacao" />

    <p:commandButton value="Cancelar" 
                     actionListener="#{dotacaoBean.cancelar}"
                     immediate="true"/>

</h:form>


